package com.tianpengcc.controller.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tianpengcc.component.InitComponent;
import com.tianpengcc.entity.Link;
import com.tianpengcc.service.LinkService;
import com.tianpengcc.util.EasyuiUtil;

@Controller
@RequestMapping("/admin/link")
public class AdminLinkController {
	
	@Resource
	private LinkService linkService ;
	
	@Resource
	private InitComponent initComponent ;
	
	@ResponseBody
	@RequestMapping("/linkManager")
	public EasyuiUtil<Link> linkManager(Integer page,Integer rows){
		EasyuiUtil<Link> easyUI = linkService.findEasyUI(page, rows);
		
		return easyUI ;
	}
	
	
	@RequestMapping(value="/linkManagerUI",method={RequestMethod.GET})
	public String linkManagerUI(){
		return "background/link/linkManager" ;
	}
	
	@ResponseBody
	@RequestMapping("/add")
	public boolean add(Link link,HttpSession session){
		boolean flag = linkService.doCreate(link);
		if(flag){
			initComponent.setServletContext(session.getServletContext()) ;
		}
		return flag ;
	}
	
	@ResponseBody
	@RequestMapping("/edit")
	public boolean edit(Link link,Integer id,HttpSession session){
		link.setId(id) ;
		boolean flag = linkService.doUpdate(link);
		if(flag){
			initComponent.setServletContext(session.getServletContext()) ;
		}
		return flag ;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public boolean delete(String idStr,HttpSession session){
		boolean flag = linkService.doDelete(idStr) ;
		if(flag){
			initComponent.setServletContext(session.getServletContext()) ;
		}
		return flag ; 
	}
}
